//导入request.js请求工具
import request from '@/utils/request.js'

// 获取活动列表
export const getActivities = (params) => {
  return request({
    url: '/admins/activities/getActivities',
    method: 'get',
    params
  })
}


// 更新活动状态
export const updateActivityStatus = (params) => {
    return request({
      url: '/admins/activities/updateStatus',
      method: 'get',
      params
    })
  }

// 获取活动详情
export const getActivityDetail = (aid) => {
  return request({
    url: `/admins/activities/getActivity/${aid}`,
    method: 'get'
  })
}

// 导出活动数据
export function exportActivities(sortType, startDate,endDate,status, searchText) {
  const params = new URLSearchParams({
    sortType: sortType || 'asc',
    startDate: startDate || '',
    endDate: endDate || '',
    status: status || '',
    searchText: searchText || ''
  }).toString();

  return request({
    url: `/admins/activities/exportActivities?${params}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000,
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
  });
}

// 获取活动发布趋势数据（添加日期范围参数）
export const getActivityTrend = (startDate, endDate) => {
  const params = {}
  if (startDate) params.startDate = startDate
  if (endDate) params.endDate = endDate
  
  return request({
    url: '/admins/activities/trend',
    method: 'get',
    params
  })
}

// 导出活动变化趋势数据
export const exportActivityTrendData = (startDate, endDate) => {
  const params = new URLSearchParams()
  if (startDate) params.append('startDate', startDate)
  if (endDate) params.append('endDate', endDate)
  
  return request({
    url: `/admins/activities/exportTrendData?${params.toString()}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000,
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
  })
}

